package com.ruoyi.project.channel.channelOrder.service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.channel.channelOrder.mapper.ChannelOrderMapper;
import com.ruoyi.project.channel.channelOrder.domain.ChannelOrder;
import com.ruoyi.project.channel.channelOrder.service.IChannelOrderService;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;

/**
 * 通道订单 服务层实现
 *
 * @author ruoyi
 * @date 2019-04-09
 */
@Service
public class ChannelOrderServiceImpl implements IChannelOrderService {
    @Autowired
    private ChannelOrderMapper channelOrderMapper;

    /**
     * 查询通道订单信息
     *
     * @param orderId 通道订单ID
     * @return 通道订单信息
     */
    @Override
    public ChannelOrder selectChannelOrderById(String orderId) {
        return channelOrderMapper.selectChannelOrderById(orderId);
    }
    /**
     * 获取当前账号的总收款金额
     * @param account
     * @return
     */
    public ChannelOrder selectAccountAmountSum(String account){
        return channelOrderMapper.selectAccountAmountSum(account);
    }
    /**
     * 查询通道订单列表
     *
     * @param channelOrder 通道订单信息
     * @return 通道订单集合
     */
    @Override
    public List<ChannelOrder> selectChannelOrderList(ChannelOrder channelOrder) {
        return channelOrderMapper.selectChannelOrderList(channelOrder);
    }

    /**
     * 查询通道订单列表 根据创建时间倒序
     *
     * @param channelOrder 通道订单信息
     * @return 通道订单集合
     */
    public List<ChannelOrder> selectChannelOrderListOrderByCreateTime(ChannelOrder channelOrder){
        return channelOrderMapper.selectChannelOrderListOrderByCreateTime(channelOrder);
    }

    /**
     * 查询通道异常订单列表
     *
     * @param channelOrder 通道订单信息
     * @return 通道订单集合
     */
    public List<ChannelOrder> selectChannelOrderErrorList(ChannelOrder channelOrder){
        return channelOrderMapper.selectChannelOrderErrorList(channelOrder);
    }
    /**
     * 新增通道订单
     *
     * @param channelOrder 通道订单信息
     * @return 结果
     */
    @Override
    public int insertChannelOrder(ChannelOrder channelOrder) {
        // ptOrderno
        channelOrder.setCreateTime(new Date());
        channelOrder.setSubmitTime(new Date());
        channelOrder.setCreateBy(channelOrder.getPayType());
        return channelOrderMapper.insertChannelOrder(channelOrder);
    }

    /**
     * 修改通道订单
     *
     * @param channelOrder 通道订单信息
     * @return 结果
     */
    @Override
    public int updateChannelOrder(ChannelOrder channelOrder) {
//        channelOrder.setUpdateBy(ShiroUtils.getLoginName());
        return channelOrderMapper.updateChannelOrder(channelOrder);
    }

    /**
     * 删除通道订单对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteChannelOrderByIds(String ids) {
        return channelOrderMapper.deleteChannelOrderByIds(Convert.toStrArray(ids));
    }

    @Override
    public List<ChannelOrder> selectOrderListNormal(ChannelOrder channelOrder) {
        // TODO Auto-generated method stub
        return channelOrderMapper.selectChannelOrderListNormal(channelOrder);
    }

    @Override
    public int setpay(String ids) {
        // TODO Auto-generated method stub
        return channelOrderMapper.setpay(Convert.toStrArray(ids));
    }
    /**
     * 更新红包结果
     * @param channelOrder
     * @return
     */
    @Override
    public int updateRedPackage(ChannelOrder channelOrder){
        return channelOrderMapper.updateRedPackage(channelOrder);
    }
}
